package com.mdd.front.controller;


import com.mdd.common.core.PageResult;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.comment.IGoodsCommentService;
import com.mdd.front.validate.comment.GoodsCommentPageParam;
import com.mdd.front.validate.comment.GoodsCommentParam;
import com.mdd.front.vo.comment.CommentParam;
import com.mdd.front.vo.comment.GoodsCommentListVo;
import com.mdd.front.vo.goods.StatisticsGoodsCommentVo;
import com.mdd.front.vo.goods.StatisticsGoodsUserCommentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 服务评价管理
 */
@Api(tags = "服务评价管理")
@RestController
@RequestMapping("api/comment")
public class GoodsCommentController {

    @Resource
    IGoodsCommentService iGoodsCommentService;

    /**
     * 服务评价列表
     *
     * @param params 搜索参数
     * @return Object
     */
    @ApiOperation(value = "服务评价管理 - 列表")
    @PostMapping("/list")
    public PageResult<GoodsCommentListVo> list(@RequestBody GoodsCommentPageParam params) {
        return iGoodsCommentService.list(params);
    }

    /**
     * 待服务评价列表 ==>使用订单分页接口(状态为已完成)
     *
     * @return Object
     */
    @ApiModelProperty(value = "服务评价管理 - 用户的评价")
    @GetMapping("/statistics/user")
    public StatisticsGoodsUserCommentVo statistics() {
        Long userId = Long.valueOf(LikeFrontThreadLocal.getUserId());
        Assert.notNull(userId, "用户信息为空");
        return iGoodsCommentService.statistics(userId);
    }

    @ApiModelProperty(value = "服务评价管理 - 服务的评价")
    @GetMapping("/statistics/goods")
    public StatisticsGoodsCommentVo statisticsGoods(@RequestParam("goodsId") Long goodsId) {
        return iGoodsCommentService.statisticsGoods(goodsId);
    }

    /**
     * 服务评价新增
     *
     * @param goodsCommentParam 参数
     * @return Object
     */
    @ApiModelProperty(value = "服务评价管理 - 服务评价新增")
    @PostMapping("/add")
    public void add(@Validated(value = GoodsCommentParam.create.class) @RequestBody GoodsCommentParam goodsCommentParam) {
        iGoodsCommentService.add(goodsCommentParam);
    }

    /**
     * 刷评论
     *
     * @param params 搜索参数
     * @return Object
     */
    @ApiOperation(value = "服务评价管理 - 列表")
    @PostMapping("/addGoodsComment")
    public void addGoodsComment(@RequestBody CommentParam params) {
        iGoodsCommentService.addGoodsComment(params);
    }

}
